package com.example.a12138.myapplication;

import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.text.InputFilter;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Switch;
import android.widget.Toast;

import com.example.a12138.myapplication.model.User;
import com.example.a12138.myapplication.presenter.UserPresenter;
import com.xdw.mvp.pv.PresentView;

public class MainActivity extends AppCompatActivity implements View.OnClickListener{
    private Button btnLogin,btnRegister;
    private EditText etUsername,etPassword;
    private static final String TAG="MainActivity";
    private UserPresenter userPresenter;
    private PresentView<User> presentView=new PresentView<User>() {
        @Override
        public void onSuccess(User user) {
            Toast.makeText(MainActivity.this, "登录成功", Toast.LENGTH_SHORT).show();
        }
    };

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        btnLogin= findViewById(R.id.btnLogin);
        btnRegister=findViewById(R.id.btnRegister);
        etUsername=findViewById(R.id.etUsername);
        etPassword=findViewById(R.id.etPassword);

        initPresenter();

        btnLogin.setOnClickListener(this);
        btnRegister.setOnClickListener(this);

    }


    private void login(){

    }

    @Override
    public void onClick(View view) {
       // Toast.makeText(this, "点击了登录按钮", Toast.LENGTH_SHORT).show();
        Log.e(TAG,"点击了登录按钮");
        /*switch (view.getId()){
            case R.id.btnLogin:;
                if("admin".equals(etUsername.getText().toString()) && "123456".equals(etPassword.getText().toString())){
                    Toast.makeText(this, "登录成功", Toast.LENGTH_SHORT).show();
                    Intent intent=new Intent(MainActivity.this,PullLoadMoreActivity.class);
                    Bundle bundle=new Bundle();
                    bundle.putString("username",etUsername.getText().toString());
                    intent.putExtras(bundle);
                    //intent.putExtra("password",etPassword.getText().toString());  //直接往intent中存入数据
                    startActivity(intent);     //第一个当前界面，第二个目标界面
                } else {
                    Toast.makeText(this, "用户名或者密码错误", Toast.LENGTH_SHORT).show();
                }

                break;
            case R.id.btnRegister:;
                Toast.makeText(this, "跳转到注册页面", Toast.LENGTH_SHORT).show();
                break;


        }*/
        userPresenter.login(etUsername.getText().toString(),etPassword.getText().toString());

    }

    public void initPresenter(){
        userPresenter=new UserPresenter(this);
        userPresenter.onCreate();
        userPresenter.BindPresentView(presentView);
    }

}
